#ifndef wm_geom_h
#define wm_geom_h
/*
 * Sylvain BERTRAND <digital.ragnarok@gmail.com>
 * code protected by GNU GPL v3
 */
struct wm_gravity_coord {
	gint pos;
	gint denom;
	gboolean center;
	gboolean opposite;
};
struct wm_gravity_point {
	struct wm_gravity_coord x;
	struct wm_gravity_coord y;
};
#define GRAVITY_COORD_SET(c, p, cen, opp) \
    (c).pos = (p), (c).center = (cen), (c).opposite = (opp)
struct wm_point {
	int x;
	int y;
};
#define POINT_SET(pt, nx, ny) (pt).x = (nx), (pt).y = (ny)
struct wm_size {
	int width;
	int height;
};
#define SIZE_SET(sz, w, h) (sz).width = (w), (sz).height = (h)
struct wm_rect {
	int x;
	int y;
	int width;
	int height;
};
#define RECT_LEFT(r) ((r).x)
#define RECT_TOP(r) ((r).y)
#define RECT_RIGHT(r) ((r).x + (r).width - 1)
#define RECT_BOTTOM(r) ((r).y + (r).height - 1)
#define RECT_SET_SIZE(r, w, h) (r).width = (w), (r).height = (h)
#define RECT_SET(r, nx, ny, w, h) (r).x = (nx), (r).y = (ny), (r).width = (w), (r).height = (h)
#define RECT_EQUAL(r1, r2) ((r1).x == (r2).x && (r1).y == (r2).y && (r1).width == (r2).width && (r1).height == (r2).height)
#define RECT_TO_DIMS(r, x, y, w, h) (x) = (r).x, (y) = (r).y, (w) = (r).width, (h) = (r).height
#define RECT_CONTAINS(r, px, py) ((px) >= (r).x && (px) < (r).x + (r).width && (py) >= (r).y && (py) < (r).y + (r).height)
#define RECT_INTERSECTS_RECT(r, o) ((o).x < (r).x + (r).width && (o).x + (o).width > (r).x && \
	(o).y < (r).y + (r).height && (o).y + (o).height > (r).y)
#define RECT_SET_INTERSECTION(r, a, b) \
    ((r).x = MAX((a).x, (b).x), \
     (r).y = MAX((a).y, (b).y), \
     (r).width = MIN((a).x + (a).width - 1, \
                     (b).x + (b).width - 1) - (r).x + 1, \
     (r).height = MIN((a).y + (a).height - 1, \
                      (b).y + (b).height - 1) - (r).y + 1)
struct strut {
	int left;
	int top;
	int right;
	int bottom;
};
struct strut_partial {
	int left;
	int top;
	int right;
	int bottom;
	int left_start, left_end;
	int top_start, top_end;
	int right_start, right_end;
	int bottom_start, bottom_end;
};
#define STRUT_SET(s, l, t, r, b) (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b)
#define STRUT_PARTIAL_SET(s, l, t, r, b, ls, le, ts, te, rs, re, bs, be) \
    (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b), \
    (s).left_start = (ls), (s).left_end = (le), \
    (s).top_start = (ts), (s).top_end = (te), \
    (s).right_start = (rs), (s).right_end = (re), \
    (s).bottom_start = (bs), (s).bottom_end = (be)
#define STRUT_EXISTS(s1) ((s1).left || (s1).top || (s1).right || (s1).bottom)
#define STRUT_EQUAL(s1, s2) \
    ((s1).left == (s2).left && \
     (s1).top == (s2).top && \
     (s1).right == (s2).right && \
     (s1).bottom == (s2).bottom)
#define PARTIAL_STRUT_EQUAL(s1, s2) \
    ((s1).left == (s2).left && \
     (s1).top == (s2).top && \
     (s1).right == (s2).right && \
     (s1).bottom == (s2).bottom && \
     (s1).left_start == (s2).left_start && \
     (s1).left_end == (s2).left_end && \
     (s1).top_start == (s2).top_start && \
     (s1).top_end == (s2).top_end && \
     (s1).right_start == (s2).right_start && \
     (s1).right_end == (s2).right_end && \
     (s1).bottom_start == (s2).bottom_start && \
     (s1).bottom_end == (s2).bottom_end)
#define RANGES_INTERSECT(r1x, r1w, r2x, r2w) (r1w && r2w && r1x < r2x + r2w && r1x + r1w > r2x)
#endif
